package com.tencent.wxcloudrun.service.impl;

import cn.hutool.core.date.DateUtil;
import com.tencent.wxcloudrun.dao.CommentMapper;
import com.tencent.wxcloudrun.model.Comment;
import com.tencent.wxcloudrun.model.Post;
import com.tencent.wxcloudrun.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lichongbing
 * @version 1.0.0
 * @createdate 2023/2/18 15:20
 * @description: TODO
 */
@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentMapper commentMapper;
    @Override
    public int addComent(Comment comment) {
        String date = DateUtil.format(DateUtil.date(), "yyyy-MM-dd HH:mm:ss");
        comment.setDate(date);
        int i = commentMapper.addComment(comment);
        return i;
    }

    @Override
    public List<Comment> getcomment(int page, int limit, int postid) {

        Map<String, Object> data = new HashMap<>();
        data.put("currIndex", (page-1)*page);
        data.put("pageSize", limit);
        data.put("postid", postid);

        return commentMapper.getcomment(data);
    }

    @Override
    public List<Post> getcommentByOpenid(String openid) {
        return commentMapper.getcommentbyopenid(openid);
    }

    @Override
    public List<Post> getpostmylikeByOpenid(String openid) {
        return commentMapper.getpostmylikeByOpenid(openid);
    }

    @Override
    public int updateaddressbyopenid(String openid, String address, String town, int id) {
        return commentMapper.updateaddressbyopenid(openid,address,town, id);
    }
}
